<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/19
 * Time: 10:56
 */

namespace app\admin\controller\user;

use app\common\controller\Backend;
class Recharge extends Backend
{
    /**
     * Record模型对象
     * @var \app\admin\model\wallet\Record
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\wallet\Record;
        $this->view->assign("payStatusList", $this->model->getPayStatusList());
    }
    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->with(['log','operation_a'])
                ->with(['user'=>function($q){
                    $q->where('group_id',2);
                }])
                ->where('type','in',[1,5,7,8])
                //->order($sort, $order)
                ->count();
            $list = $this->model
                ->with(['log','operation_a'])
                ->with(['user'=>function($q){
                    $q->where('group_id',2);
                }])
                ->where($where)
                ->where('type','in',[1,5,7,8])
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $list = collection($list)->toArray();
            foreach ($list as $k=>$v){
                if( $v['type'] == 1 ){
                    $list[$k]['type'] = '微信充值';
                }
                if( $v['type'] == 5 ){
                    $list[$k]['type'] = '赠送';
                }
                if( $v['type'] == 8 ){
                    $list[$k]['type'] = '支付宝充值';
                }
                if( $v['type'] == 7 ){
                    $list[$k]['type'] = '银行转账';
                }
                if( !$v['operation_a'] ){
                    $list[$k]['operation_name'] = '系统';
                }else{
                    $list[$k]['operation_name'] = $v['operation_a']['username'];
                }
                if( $v['user']['group_id'] == 1 ){
                    $list[$k]['user']['role_name'] = '系统账号';
                }
                if( $v['user']['group_id'] == 2 ){
                    $list[$k]['user']['role_name'] = '玩家';
                }
                if( $v['user']['group_id'] == 3 ){
                    $list[$k]['user']['role_name'] = '代理';
                }
            }
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }
}